// 处理时间的封装
/**
 * 获取现在的日期+时间,格式为:1900-01-01 23:59:59
 * @param 
 * @returns
 */
function nowtime(){
	var times = null
	let year = new Date().getFullYear();
	let month = new Date().getMonth() + 1;
	let days = new Date().getDate();
	let hour = new Date().getHours()
	let minutes = new Date().getMinutes()
	let second = new Date().getSeconds()
	if (month < 10) { month = '0' + month }
	if (days < 10) { days = '0' + days }
	if (hour < 10) { hour = '0' + hour }
	if (minutes < 10) {minutes = '0' + minutes }
	if (second < 10) { second = '0' + second }
	return times = year + '-' + month + '-' + days + ' ' + hour + ':' + minutes + ':' + second
}
/**
 * 获取今天现在的时间,格式为:23:59:59
 * @param 
 * @returns
 */
function nowday(){
	var times = null
	let hour = new Date().getHours()
	let minutes = new Date().getMinutes()
	let second = new Date().getSeconds()
	if (hour < 10) { hour = '0' + hour }
	if (minutes < 10) {minutes = '0' + minutes }
	if (second < 10) { second = '0' + second }
	return times = hour + ':' + minutes + ':' + second
}
/**
 * 获取现在的日期,格式为:1900-01-01
 * @param 
 * @returns
 */
function nowDate(){
	var times = null
	let year = new Date().getFullYear();
	let month = new Date().getMonth() + 1;
	let days = new Date().getDate();
	if (month < 10) { month = '0' + month }
	if (days < 10) { days = '0' + days }
	return times = year + '-' + month + '-' + days
}
/**
 * 传入对应时间戳返回分秒的形式,例:传入(900000)返回15:00
 * @param time
 * @returns 
 */
function GetMintesSeconds(time){
	var times = null
	let minutes = new Date(time).getMinutes()
	let second = new Date(time).getSeconds()
	if (minutes < 10) {minutes = '0' + minutes }
	if (second < 10) { second = '0' + second }
	return times = minutes+':'+second
}
/**
 * 传入对应时间戳返回时分秒的形式,例:传入(3660000)返回01:01:00
 * @param time
 * @returns 
 */
function GetHourMintesSeconds(time){
	var times = null
	let minutes = new Date(time).getMinutes()
	let second = new Date(time).getSeconds()
	if (minutes < 10) {minutes = '0' + minutes }
	if (second < 10) { second = '0' + second }
	if(time<3600000){
		return times = minutes+':'+second
	}else{
		let hour = new Date(time).getHours()
		if (hour < 10) { hour = '0' + hour }
		return times = hour+':'+minutes+':'+second
	}
}
/**
 * 将时间戳格式的字符串转格式为:1900-01-01 23:59:59
 * @param timestamp
 * @returns
 */
function TimestampConversion(timestamp){
	 timestamp = timestamp ? timestamp : null;
	    let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	    let Y = date.getFullYear() + '-';
	    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
	    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
	    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
	    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
	    return Y + M + D + h + m + s;
}
/**
 * 获取当前时间段的名称 例:早晨,晚上,
 * @param hour
 * @returns
 */
function GetNowHourTamp(){
	 var time = new Date()
	 var hour = time.getHours()
	 var nowHourTamp = ''
	    if(hour>=6&&hour<8){
	    	nowHourTamp = '早晨'
	    }else if(hour>=8&&hour<11){
	    	nowHourTamp = '上午'
	    }else if(hour>=11&&hour<13){
	    	nowHourTamp = '中午'
	    }else if(hour>=13&&hour<17){
	    	nowHourTamp = '下午'
	    }else if(hour>=17&&hour<19){
	    	nowHourTamp = '傍晚'
	    }else if(hour>=19&&hour<23){
	    	nowHourTamp = '晚上'
	    }else if(hour>=23){
	    	nowHourTamp = '凌晨'
	    }
	    return nowHourTamp
}
module.exports = {
	nowtime,
	nowDate,
	nowday,
	GetHourMintesSeconds,
	TimestampConversion,
	GetNowHourTamp
}